//
//  LGAlertView.m
//  MindBox
//
//  Created by MS on 16-1-14.
//  Copyright (c) 2016年 Lemon. All rights reserved.
//

#import "LGAlertView.h"

@interface LGAlertView ()

@property (nonatomic,weak) UILabel * label ;
@property (nonatomic,weak) UIView * baseView ;
@end

@implementation LGAlertView

-(void)setTitle:(NSString *)title
{
    _title = title;
     self.label.text = title;
}

+(instancetype)showWithTitle:(NSString *)title
{
    LGAlertView * view = [[self alloc] init];
    view.label.text = title;
   
    [[UIApplication sharedApplication].keyWindow addSubview:view];
    return view;
}

+(instancetype)show
{
    return [[self alloc] init];
}

-(instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor clearColor];
        
        UIView * view = [[UIView alloc] init];
        [self addSubview:view];
        
        view.backgroundColor = [UIColor blackColor];
        
        view.layer.opacity = 0.7;
        view.layer.cornerRadius = 5;
        view.clipsToBounds = YES;
        view.frame = self.bounds;
        self.baseView = view;
        
        UILabel * label = [[UILabel alloc] init];
        label.textColor =[UIColor whiteColor];
      
        label.textAlignment = NSTextAlignmentCenter;
        label.font = [UIFont systemFontOfSize:12];
        label.numberOfLines = 0;
        self.label = label;
        [self addSubview:label];
        
    }
    return self;
}

-(void)willMoveToSuperview:(UIView *)newSuperview
{
    [super willMoveToSuperview:newSuperview];
    self.frame = CGRectMake(0, 0, 100, 80);
    self.center = CGPointMake(newSuperview.frame.size.width*0.5, newSuperview.frame.size.height*0.5);

    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.label.frame=CGRectMake(0, 0, 80, 40);
    self.label.center= CGPointMake(self.frame.size.width*0.5, self.frame.size.height*0.5);
    self.baseView.frame = self.bounds;
}

@end
